package com.gzu;

import java.sql.Connection;
import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {
        // 调用DBConnection类来获取数据库连接
        try (Connection conn = DBConnection.getConnection()) {
            // 测试批量插入
            batchInsertTeachers(conn);

            // 测试CRUD操作
            deleteTeacher(conn, 100);
            readTeacher(conn, 1);
            updateTeacher(conn, 1, "New Teacher Name", "New Course Name", "1990-01-01");
            readTeacher(conn, 1);
            createTeacher(conn, 100);

            // 测试可滚动结果集
            scrollableResultSet(conn);

            System.out.println("Database operations completed successfully.");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    private static void createTeacher(Connection conn, int id) {
        // 调用TeacherCRUD类的createTeacher方法
        TeacherCRUD.createTeacher(conn, id,"John Doe", "Mathematics", "1980-01-01");
    }

    private static void readTeacher(Connection conn, int id) {
        // 调用TeacherCRUD类的readTeacher方法
        TeacherCRUD.readTeacher(conn, id);
    }

    private static void updateTeacher(Connection conn, int id, String name, String course, String birthday) {
        // 调用TeacherCRUD类的updateTeacher方法
        TeacherCRUD.updateTeacher(conn, id, name, course, birthday);
    }

    private static void deleteTeacher(Connection conn, int id) {
        // 调用TeacherCRUD类的deleteTeacher方法
        TeacherCRUD.deleteTeacher(conn, id);
    }

    private static void batchInsertTeachers(Connection conn) {
        // 调用TeacherBatchInsert类的batchInsertTeachers方法
        TeacherBatchInsert.batchInsertTeachers(conn);
    }

    private static void scrollableResultSet(Connection conn) {
        // 调用TeacherScrollableResultSet类的scrollableResultSet方法
        TeacherScrollableResultSet.scrollableResultSet(conn);
    }
}